//
//  TKUtil.h
//  Trackit
//
//  Created by yaodaobin on 2017/4/2.
//  Copyright © 2017年 yaodaobin. All rights reserved.
//

#import <Foundation/Foundation.h>



#define MMBANG_NETWORK_ERR_WEINAI @"请稍候..."
#define MMBANG_NETWORK_ERR_UNSTABLE @"网络不太给力哦~"


@class SegmentedControl;

//#import "User.h"
typedef void(^ProcessStringBlock)(NSString *msg);
typedef void (^frameBlock)(UIView *);

@interface TKUtil : NSObject
+ (void)showMessageFromServer:(id)data defaultMsg:(NSString *)message;
+ (void)showMessage:(NSString *)message;
+ (void)showMessage:(NSString *)message withOffset:(CGFloat)offset;
+ (BOOL)isNumberFromString:(NSString *)rawString;

+ (UIImage *)limiteSizeWithImage:(UIImage *)rawImage;
+ (UIImage *)resizeImageWithRawImage:(UIImage*)image scaledToSize:(CGSize)newSize;
+ (UIImage *)restrictImage:(UIImage *)image inSize:(CGFloat)size;
+ (BOOL)writeImage:(UIImage*)image toFileAtPath:(NSString*)aPath;
+ (BOOL)isNetworkAvailable;
+ (void)showNetworkErrorMsg:(NSError *)error isPop:(BOOL)isPop;
+ (void)processNetworkErrorMsg:(NSError *)error block:(ProcessStringBlock)block;
//+ (NSString *)getNetworkErrorMsg:(NSError *)error; //use processNetworkErrorMsg:block instead

+ (NSArray *)splitString:(NSString *)rawString withMaxLength:(NSInteger)maxLength;

#pragma mark - 最少返回12像素
+ (CGFloat)heightForText:(NSString*)contentText width:(CGFloat)width font:(UIFont *)font;
#pragma mark - 根据字体，宽度返回 高度
+ (CGFloat)heightWithText:(NSString *)text font:(UIFont *)font width:(CGFloat)width minHeight:(CGFloat)minHeight;
+ (CGFloat)widthWithText:(NSString *)text font:(UIFont *)font height:(CGFloat)height minWidth:(CGFloat)minWidth;

// 计算文本尺寸
+ (CGSize)sizeWithText:(NSString *)text boundingSize:(CGSize)boundingSize font:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode
;
+ (CGFloat)heightWithText:(NSString *)text boundingSize:(CGSize)boundingSize font:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode;

//字体的上下间距
+ (CGFloat)getFontSpaceWithLabel:(UIFont*)font;
+ (UIImage *)createImageFromColor:(UIColor *)color;
+ (UIImage *)createImageFromColor:(UIColor *)color withSize:(CGSize)size;
+ (NSString *)trimWhitespace:(NSString *)string;
+ (UIViewAnimationOptions)animationOptionsForCurve:(UIViewAnimationCurve)curve;
+ (UIImage*)convertImageToGreyScale:(UIImage*) image;

#pragma mark 路径，存储
+ (NSURL *)getApplicationDocumentsDirectory;
+ (NSString *)getDocumentPath:(NSString *)lastFolderName;
/**
 *  返回 Document 下，当前用户的目录
 *
 *  @param lastFolderName 需要跟的文件
 *
 *  @return <#return value description#>
 */
+ (NSString *)getUserDocumentPath:(NSString *)lastFolderName;

+ (void)saveDataWithKey:(NSString *)key ofValue:(id)value;
+ (void)clearDataWithKey:(NSString *)key;
+ (id)getDataWithKey:(NSString *)key;

+ (void)saveEntityWithKey:(NSString *)key ofValue:(id)value;
+ (id)getEntityWithKey:(NSString *)key;

+ (void)saveLoginUserInfo:(User *)user;
+ (User *)getLoginUserInfo;
+ (void)clearLoginUserInfo;
+ (BOOL)judgePhotoPerm;
+ (BOOL)hasReadedGuide;
+ (void)readGuide;
+ (BOOL)isOldUser;

#pragma mark 存储 O2O 景区信息
+ (NSDictionary *)getO2OAllScenices;
+ (NSDictionary *)getO2OScenicDataWithCityID:(NSString *)cityID;
+ (BOOL)saveO2OScenicData:(NSDictionary *)dictionary;

#pragma mark - 存储 位置搜索的历史记录
+ (NSArray *)getO2OLocationSearchHistory;
+ (BOOL)saveO2OLocationSearchHistory:(NSDictionary *)dictionary;
+ (BOOL)cleanO2OLocationSearchHistory;

+ (NSString *)jsonStringWithObject:(id)object;

+ (BOOL)isEqualFromString:(NSString *)from toString:(NSString *)toString;

+ (NSString *)macAddress;

BOOL isValidatePhone(NSString * candidate);

BOOL isValidateEmail(NSString * candidate);

//将fffff转化为uicolor
UIColor * colorWithHexString(NSString *stringToConvert);

NSString* getBabyGenerType(NSString*string);

void setExclusiveTouchToChildrenOf(NSArray *subviews);


void writeToPlist(NSString *strPlistName, NSData *arrData)
;
NSString * getPlistName(NSString *strPlistName);
void removePlist(NSString *strPlistName);

// Register UIWebView UserAgent

+ (void)registerUIWebViewUserAgent;
+ (void)unregisterUIWebViewUserAgent;

// UITextField Limit Lenght

+ (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string limitMaxLength:(NSUInteger)maxLength;

+ (void)saveUserInfoWithServerData:(NSDictionary *)data dismissLoginNav:(BOOL)dismiss;

/**
 *  应用程序的名称
 *
 *  @return NSString
 */
+ (NSString *)appName;

#pragma mark -
#pragma mark 判断字符串是否为空（nil和length为0都是空）

+ (BOOL)isEmpty:(NSString *)value;

+ (BOOL)isHostAvailable:(NSString *)hostname;

+ (NSString *)getScreenSize;

+ (void)updateSysUserInfo:(User *)user;

+ (UILabel *)createLabel:(UIFont *)textFont color:(UIColor *)textColor;

+ (UILabel *)creatSizeFitLabelWithFont:(UIFont *)font color:(UIColor *)color superView:(UIView *)superView;

// 格式化距离
+ (NSString *)formatDistanceWithMeters:(double)meters;

/**
 *  从cover字典里取根据屏幕尺寸匹配的image url
 *
 *  @param dict cover字典
 *
 *  @return 正确的image url
 */

+ (NSString *)preferedImageFromImagesDict:(NSDictionary *)dict;

+ (UIImage *)createDefaultO2OImageInView:(UIView *)parentView;
+ (UIImage *)createDefaultImage:(NSString *)defaultImageName InView:(UIView *)parentView;
+ (UIImage *)createDefaultImage:(NSString *)defaultImageName withSize:(CGSize )size;
+ (float) heightForTextView: (UITextView *)textView WithText: (NSString *) strText;

/**
 *  计算文件大小
 *
 *  @param path 路径
 *
 *  @return 正确的image url
 */

+ (NSString *)folderSizeAtPath:(NSString *)path;

//是否支持手势滑动，popViewController
+ (void)isCanDragBack:(BOOL)isBack;

+ (BOOL)emptyOrNull:(NSString *)str;

#pragma mark - 生成 UUID
+ (NSString *)createUUID;

+ (NSString *)deviceModel;
+ (NSString *)deviceModelOrigin;

+ (UIView *)generateBadgeLabel:(NSInteger)number colorful:(BOOL)colorful;

#pragma mark -- createFilePath

+ (NSString *)folderPath:(NSString*)folderPath;

+ (NSString *)createFolderPathIfNeeded:(NSString*)folderPath;

+ (void)cleanFolderPath:(NSString*)folderPath;

+ (SegmentedControl *)createViewContent:(NSArray *)configureData titleColor:(UIColor *)titleColor;

+ (BOOL)canHandlePush;

+ (BOOL)isDate:(NSDate *)date1 sameDayToDate:(NSDate *)date2 format:(NSString *)format;

+ (void)openURL:(NSURL *)url;

+ (NSArray *)calsInvalidDaysForYear:(int)year month:(int)month day:(int)day;

+ (CGFloat)getTheProportionNewSpaceWithScreenWidth:(CGFloat)space;

/**
 *  获取mobile网络类型
 *
 *  @return e.g. 2G/3G/4G
 */
+ (NSString *)dataNetworkTypeFromStatusBar;
/**
 获取不可见区域可滚动视图contentsize的截图
 *scale 屏幕 1X 2X 3X
 *quality 图片压缩比 0.0 ~ 1.0   1.0为原图最清晰
 *opaque 是否透明
 */
+ (UIImage *)captureWholeScrollViewContentWithScreenScale:(CGFloat)scale compressionQuality:(CGFloat)quality isOpaque:(BOOL)opaque scrollView:(UIScrollView *)scrollView;
/**
 *images : 按顺序从上往下拼接图片
 *cutHeight : 底部需要裁剪掉的高度
 */
+ (UIImage *)getverticalMontageWithImages:(NSArray<UIImage*> *)images cutBottomHeight:(CGFloat)cutBottomHeight;
/**
 *images : 按顺序从上往下拼接图片
 *cutHeight : 顶部需要裁剪掉的高度
 */
+ (UIImage *)getverticalMontageWithImages:(NSArray<UIImage*> *)images cutTopHeight:(CGFloat)cutTopHeight;

@end
